package com.fhx.core

import android.content.pm.ApplicationInfo
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.text.TextUtils
import android.util.Log


class AppConfig {
    companion object {
        var mVersion: String? = null
        //内部存储 /data/data/<application package>/files目录
        //val INNER_PATH: String = AppContext.instance.filesDir.absolutePath
        val APK_PATH: String = "/apk/"

        private fun getMetaDataString(key: String): String? {
            var res: String? = null
            try {
                val appInfo: ApplicationInfo = AppContext.instance.packageManager
                    .getApplicationInfo(
                        AppContext.instance.packageName,
                        PackageManager.GET_META_DATA
                    )
                res = appInfo.metaData.getString(key)
            } catch (e: PackageManager.NameNotFoundException) {
                e.printStackTrace()
            }
            return res
        }

        /**
         * 获取版本号
         */
        fun getVersion(): String? {
            if (TextUtils.isEmpty(mVersion)) {
                try {
                    val manager: PackageManager = AppContext.instance.packageManager
                    val info: PackageInfo =
                        manager.getPackageInfo(AppContext.instance.packageName, 0)
                    mVersion = info.versionName
                } catch (e: Exception) {
                    e.printStackTrace()
                }
            }
            Log.e("TAG", "getVersion22222222222222222222222: " +  mVersion)
            return mVersion
        }
    }
}